package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.ApproveHisVO;
import com.yunxi.sto.service.ApproveHisDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 审核历史 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-09-03
 */
@RestController
@RequestMapping("/admin/approveHis")
@Api(tags = "sto:approveHis", description = "审核历史接口")
public class ApproveHisController {
    private static final Logger logger = LoggerFactory.getLogger(ApproveHisController.class);

    @Autowired
    ApproveHisDubboService approveHisDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询审核历史分页")
    public ApiResult page(ApproveHisVO approveHisVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(approveHisDubboService.findPageByVO(approveHisVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询审核历史列表")
    public ApiResult list(ApproveHisVO approveHisVO) throws Exception {
        return ResponseUtil.ok(approveHisDubboService.listByVo(approveHisVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个审核历史")
    public ApiResult load(ApproveHisVO approveHisVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(approveHisDubboService.getById(approveHisVO.getHisId()));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存审核历史信息")
    public ApiResult save(@RequestBody ApproveHisVO approveHisVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        approveHisDubboService.saveOrUpdate(approveHisVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除审核历史")
    public ApiResult del(@RequestBody List<ApproveHisVO> approveHisVOList) throws Exception {
        approveHisDubboService.removeByListVo(approveHisVOList);
        return ResponseUtil.ok("success");
    }

}
